import { divide } from "lodash";

// role manage column
export function roleColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      type: "selection",
      width: 50,
      align: "center"
    },
    {
      title: this.$t("module.role.roleCode"),
      key: "roleCode",
      minWidth: 180,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleCode
            }
          },
          params.row.roleCode
        );
      }
    },
    {
      title: this.$t("module.role.roleName"),
      key: "roleName",
      minWidth: 180,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleName
            }
          },
          params.row.roleName
        );
      }
    },
    {
      title: this.$t("module.role.roleType"),
      key: "roleType",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: this.roleTypeList[params.row.roleType]
            }
          },
          this.roleTypeList[params.row.roleType]
        );
      }
    },
    // {
    //   title: this.$t("module.role.sourceApplication"),
    //   key: "appId",
    //   align: "left",
    //   minWidth: 150,
    //   render: (h, params) => {
    //     return h(
    //       "div",
    //       {
    //         attrs: {
    //           class: "ivu-table-cell ivu-table-cell-ellipsis",
    //           title: params.row.roleType == 1 ? "-" : this.appList[params.row.appId]
    //         }
    //       },
    //       params.row.roleType == 1 ? "-" : this.appList[params.row.appId]
    //     );
    //   }
    // },
    {
      title: this.$t("common.describe"), // 备注 改为 描述
      key: "remark",
      minWidth: 120,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.remark
            }
          },
          params.row.remark
        );
      }
    },
    {
      title: this.$t("module.tenantManage.startTime"), // 生效日期
      key: "effectBegin",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
    },
    {
      title: this.$t("module.tenantManage.endTime"), // 失效日期
      key: "effectEnd",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
    },
    {
      title: this.$t("common.status"),
      align: "center",
      key: "enabled",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },
            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          params.row.enabled ? this.$t("common.enable") : this.$t("common.disable")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 120,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: this.getOperations(params.row)
          }
        });
      }
    }
  ];
}

export function userlistColumns() {
  return [
    {
      type: "selection",
      width: 60,
      align: "center"
    },
    {
      title: this.$t("module.role.account_LDAP"),
      key: "userCode"
    },
    {
      title: this.$t("module.userManage.account"),
      key: "userName"
    },
    {
      title: this.$t("common.status"),
      align: "left",
      key: "enabled",
      render: (h, params) => {
        const row = params.row;
        const text = row.enabled == 1 ? this.$t("common.enable") : this.$t("common.disable");

        return h(
          "StatusButton",
          {
            props: {
              status: params.row.enabled
            }
          },
          text
        );
      }
    },
    {
      title: this.$t("module.userManage.type"),
      key: "type",
      width: 140,
      render: (h, params) => {
        return h("span", this.userTypeText(params.row.type));
      }
    }
  ];
}

export function roleAppColumns() {
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    {
      title: this.$t("module.role.appCode"),
      key: "fromAppId",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.fromAppId
            }
          },
          params.row.fromAppId
        );
      }
    },
    {
      title: this.$t("module.role.appName"),
      key: "appName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.appName
            }
          },
          params.row.appName
        );
      }
    }
  ];
}

export function roleSelectColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.role.appCode"),
      key: "clientId",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.clientId
            }
          },
          params.row.clientId
        );
      }
    },
    {
      title: this.$t("module.role.appName"),
      key: "appName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.appName
            }
          },
          params.row.appName
        );
      }
    }
  ];
}

export function dimensionListColumns() {
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    {
      title: this.$t("module.dimension.name"),
      key: "dimensionDataName",
      // sortable: true,
      // width: 500,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataName
            }
          },
          params.row.dimensionDataName
        );
      }
    },
    {
      title: this.$t("module.dimension.code"),
      key: "dimensionDataCode",
      // sortable: true,
      // width: 500,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataCode
            }
          },
          params.row.dimensionDataCode
        );
      }
    }
  ];
}

export function dimensionSelectColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.dimension.name"),
      key: "name",
      width: 200,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.name
            }
          },
          params.row.name
        );
      }
    },
    {
      title: this.$t("module.dimension.code"),
      key: "code",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.code
            }
          },
          params.row.code
        );
      }
    }
  ];
}

export function roleAssignMenuColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.menuManage.menuCode"),
      key: "menuCode",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuCode
            }
          },
          params.row.menuCode
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuName"),
      key: "menuName",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuName
            }
          },
          params.row.menuName
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuType"),
      key: "menuType",
      width: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuTypeName
            }
          },
          params.row.menuTypeName
        );
      }
    },
    {
      title: this.$t("common.describe"), // module.menuManage.remark 备注 改为 描述
      key: "remark",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.remark
            }
          },
          params.row.remark
        );
      }
    }
  ];
}

export function roleSelectMenuColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.menuManage.menuCode"),
      key: "menuCode",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuCode
            }
          },
          params.row.menuCode
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuName"),
      key: "menuName",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuName
            }
          },
          params.row.menuName
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuType"),
      key: "menuType",
      width: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuTypeName
            }
          },
          params.row.menuTypeName
        );
      }
    },
    {
      title: this.$t("common.describe"), // module.menuManage.remark 备注 改为 描述
      key: "remark",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.remark
            }
          },
          params.row.remark
        );
      }
    }
  ];
}

export function roleDetailFuncGroupColumns() {
  return [
    {
      title: this.$t("module.menuManage.menuCode"),
      key: "menuCode",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuCode
            }
          },
          params.row.menuCode
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuName"),
      key: "menuName",
      width: 180,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuName
            }
          },
          params.row.menuName
        );
      }
    },
    {
      title: this.$t("module.menuManage.menuType"),
      key: "menuType",
      width: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.menuTypeName
            }
          },
          params.row.menuTypeName
        );
      }
    },
    {
      title: this.$t("common.describe"), // module.menuManage.remark 备注 改为 描述
      key: "remark",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.remark
            }
          },
          params.row.remark
        );
      }
    }
  ];
}

export function generateColumns() {
  return [
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      minWidth: 100
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.organization"), // 所属组织
      key: "orgName",
      minWidth: 110,
      align: "left",
      render: (h, params) => {
        if (params.row._hasOrgInfo) {
          return h(
            "div",
            {
              attrs: {
                class: "ivu-table-cell ivu-table-cell-ellipsis",
                title: params.row.orgNameFullPath
              }
            },
            params.row.orgName
          );
        } else {
          return h("Spin", [
            h("Icon", {
              props: {
                type: "ios-loading",
                size: 18
              },
              class: "spin-icon-load"
            })
          ]);
        }
      }
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      minWidth: 90
    },
    {
      title: this.$t("common.status"), // 状态
      align: "left",
      key: "locked",
      width: 80,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            props: {
              status: params.row.locked
            }
          },
          params.row.locked == "1" ? this.$t("common.disable") : this.$t("common.enable")
        );
      }
    }
  ];
}

export function organizationColumns() {
  return [
    {
      title: this.$t("module.role.organizationCode"),
      key: "orgCode",
      minWidth: 100
    },
    {
      title: this.$t("module.role.organizationName"),
      key: "orgName",
      minWidth: 90
    },
    {
      title: this.$t("module.role.authorizedUsersDetail"),
      key: "assignmentType",
      minWidth: 110,
      render: (h, params) => {
        return h(
          "div",
          {
            props: {
              status: params.row.assignmentType
            }
          },
          params.row.assignmentType == "1"
            ? this.$t("module.role.currentOrgOrChild")
            : this.$t("module.role.currentOrg")
        );
      }
    }
  ];
}
